import GameLogic
from middleware.yarp import YarpBlender

sensor = GameLogic.getCurrentController().getSensor('escape_key')

#execute only when the ESC key is released (if we don't test that, the code get executed two time, when pressed, and when released)
if not sensor.isPositive() and sensor.isTriggered():
	print '######### FINALIZING... ########'
	
	YarpBlender.finalize()
	quitActuator = GameLogic.getCurrentController().getActuator('quit')
	GameLogic.addActiveActuator(quitActuator, True)
	
	print '######### EXITING SIMULATION ########'